package com.onstar.cn.weight.more;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.onstar.cn.weight.R;

/**
 * Created by 7828wc on 16/6/27.
 */
public class CustomTextImageLayout extends LinearLayout {
    private View view;
    private TextView tv_text;
    private ImageView image_icon;

    public CustomTextImageLayout(Context context) {
        super(context); initView(null);
    }

    public CustomTextImageLayout(Context context, AttributeSet attrs) {
        super(context, attrs); initView(attrs);
    }

    public CustomTextImageLayout(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initView(attrs);
    }

    private void initView(AttributeSet attrs) {
        view = inflate(getContext(), R.layout.weight_icon_text, this);
        tv_text = (TextView) view.findViewById(R.id.tv_text);
        image_icon = (ImageView) view.findViewById(R.id.image_icon);

        if(attrs!=null){
            TypedArray typedArray=getContext().obtainStyledAttributes(attrs,R.styleable.input);
            String title=typedArray.getString(R.styleable.input_topTitle);
            tv_text.setText(title);

            int imgSrc=typedArray.getResourceId(R.styleable.input_src,-1);
            if(imgSrc!=-1){
                image_icon.setImageResource(imgSrc);
            }

            typedArray.recycle();
        }
    }
}
